/**
  **********************************************************************************************************************
  * @file    cot_os.h
  * @brief   该文件提供查询协作式多任务系统功能函数原型
  * @author  const_zpc    any question please send mail to const_zpc@163.com
  * @date    2025-5-11
  **********************************************************************************************************************
  *
  **********************************************************************************************************************
  */

/* Define to prevent recursive inclusion -----------------------------------------------------------------------------*/
#ifndef _COT_OS_H_
#define _COT_OS_H_

/* Includes ----------------------------------------------------------------------------------------------------------*/
#include <stdint.h>
#include <stddef.h>


// 定义一个OS预编译宏
#define _COT_OS_

/* Exported types ----------------------------------------------------------------------------------------------------*/

typedef void (*cotOsTask_f)(int);
typedef uint32_t (*cotOsGetSysTime_f)(void);

typedef struct
{
    uint8_t flag;
}CotOSCondition_t;

typedef int cotOsTask_t;

/* Exported constants ------------------------------------------------------------------------------------------------*/

#define COT_ERROR_NOT_INIT                -1
#define COT_ERROR_STACK_IS_NULL           -2
#define COT_ERROR_STACK_OVERLAPPING       -3
#define COT_ERROR_TCB_MEM_FAIL            -4
#define COT_ERROR_TCB_MEM_STACK_FAIL      -5

/* Exported macro ----------------------------------------------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------------------------------------------------*/

extern void cotOs_Init(cotOsGetSysTime_f pfnOsTimer);
extern int cotOs_Start(void);

extern cotOsTask_t cotOs_CreatTaskWithStack(cotOsTask_f pfnOsTaskEnter, const char *pName, void *pStack, size_t stackSize, int arg);
extern cotOsTask_t cotOs_CreatTask(cotOsTask_f pfnOsTaskEnter, const char *pName, int arg);
extern void cotOs_Wait(uint32_t time);
extern void cotOs_Join(cotOsTask_t task);

extern uint16_t cotOs_Pid(void);

extern void cotOs_ConditionInit(CotOSCondition_t *pCondition);
extern void cotOs_ConditionWait(CotOSCondition_t *pCondition);
extern void cotOs_ConditionNotify(CotOSCondition_t *pCondition);

extern void cotOs_Top(void);

#endif // !_COT_TASK_H_
